import Vue from 'vue'
import VueRouter from 'vue-router'
// 引入Layout组件
import Layout from '@/views/layout/index.vue'
import Login from '@/views/login/index.vue'
import Home from '@/views/home/Home.vue'

//通过异步加载方式引用组件
const Product = () => import('@/views/product/index.vue')
const List = () => import('@/views/product/list/index.vue')
const Category = () => import('@/views/product/category/index.vue')
// 订单
const Order = () => import('@/views/order/index.vue')
const orderList = () => import('@/views/order/list/index.vue')
const Collect = () => import('@/views/order/collect/index.vue')
const Familymember = () => import('@/views/order/familymember/index.vue')

// 广告
const Ad = () => import('@/views/ad/index.vue')
const Adlist = () => import('@/views/ad/adlist/index.vue')

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    // 使用Layout组件,一级路由
    component: Layout,
    // 二级路由
    children: [
      {
        path: '/',
        name: 'home',
        component: Home,
      },
      {
        path: '/product',
        name: 'product',
        component: Product,
        // 三级路由，路径不用加/
        children: [
          {
            path: 'list',
            name: 'list',
            component: List,
          },
          {
            path: 'category',
            name: 'category',
            component: Category,
          },
        ]

      },
      {
        path: '/order',
        name: 'order',
        component: Order,
        // 三级路由，路径不用加/
        children: [
          {
            path: 'list',
            name: 'list',
            component: orderList,
          },
          {
            path: 'collect',
            name: 'collect',
            component: Collect,
          },
          {
            path: 'familymember',
            name: 'familymember',
            component: Familymember,
          },
        ]

      },
      {
        path: '/ad',
        name: 'ad',
        component: Ad,
        // 三级路由，路径不用加/
        children: [
          {
            path: 'adlist',
            name: 'adlist',
            component: Adlist,
          },
        ]

      },

    ]
  },
  {
    path: '/login',
    name: 'login',
    component: Login,
  }

]


const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
